package com.atguigu.java2;

/*
 * 面向对象特征：封装与隐藏
 * 
 * 此代码为封装性的体现，只是其中一个点
 * 
 * 
 * 
 */

public class AnimalTest {
		public static void main(String[] args) {
				
				Animal a = new Animal();
				a.name = "大黄";
				//a.age = 1;
				//a.legs = - 4;The field Animal.legs is not visible
				
				a.show();
						
		}
}

class Animal{
	
		String name;
		private int age;
		private int legs;
		
		//对属性的设置
		public void setLegs(int l){
				if (l >= 0 && l % 2 == 0){
						legs = l;
				}else{
						System.out.println("error!");;
				}
		}
		//堆属性的获取
		public int getLegs(){
			return legs;
		}
		
		public void eat(){
			 System.out.println("动物进食");
		}
		
		public void show(){
				System.out.println("name = " + name + ", age = " + age + ", legs = " + legs );
		}
		
		//get与set的设置方法
		public int getAge(){
				return age;
		}
		public void setAge(int a){
				age = a;
		}
}